package com.Day11;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author: 若若叶
 * @date: 2021/7/19 15:30
 * FileName: Copy
 * Description: 文件拷贝
 */
public class Copy {
    public static void main(String[] args) {
        //新建输入流，输出流
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;

        try {
            //找到文件
            fileInputStream = new FileInputStream("E:\\bv\\名侦探柯南\\01 - 云霄飞车杀人事件.flv");
            //true表示append：在文件后面追加数据
            fileOutputStream = new FileOutputStream("E:\\bv\\01 - 云霄飞车杀人事件.flv", true);
            //设置每次读取的字节数
            byte[] bytes = new byte[1024 * 1024];
            //本次读取的字节数，-1表示为读取到
            int readcount = 0;
            while ((readcount = fileInputStream.read(bytes)) != -1) {
                //读取到，输出
                fileOutputStream.write(bytes, 0, readcount);
            }
            //刷新
            fileOutputStream.flush();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream != null) {
                try {
                    //关闭
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fileOutputStream != null) {
                try {
                    //关闭
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
